﻿using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;

namespace Colorful.Furniture.Permissions;

/// <summary>
///  自定义权限验证提供者
/// </summary>
public class FurniturePermissionValueProvider : PermissionValueProvider
{
    public FurniturePermissionValueProvider(IPermissionStore permissionStore) : base(permissionStore)
    {

    }

    /// <summary>
    ///  检查单授权
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
    {
        var result = await PermissionStore.IsGrantedAsync(context.Permission.Name, "R", "Admin");

        return result ? PermissionGrantResult.Granted : PermissionGrantResult.Prohibited;
    }

    /// <summary>
    ///  检查多授权
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    /// <exception cref="System.NotImplementedException"></exception>
    public override async Task<MultiplePermissionGrantResult> CheckAsync(PermissionValuesCheckContext context)
    {
        await Task.CompletedTask;

        return new MultiplePermissionGrantResult();
    }

    /// <summary>
    ///  名字
    /// </summary>
    public override string Name => "FurniturePermission";
}